/*
 * Copyright (c) 2008, Takashi Ito
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the authors nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <stdio.h>
#include <stdlib.h>
#include <event.h>
#include <wx/wx.h>
#include "SsdpFrame.h"

class MyTimer : public wxTimer {
public:
    MyTimer(struct event_base *evbase) : wxTimer(), count(0), evbase(evbase) {}
    void Notify();
private:
    unsigned int count;
    struct event_base *evbase;
};

void MyTimer::Notify()
{
    //printf("Notify %u\n", count++);
    event_base_loop(evbase, EVLOOP_NONBLOCK);
}

class MyApp : public wxApp {
public:
    MyApp() {}
    virtual ~MyApp() {}
    bool OnInit();
    int OnExit();
private:
    MyTimer *timer;
    struct event_base *evbase;
};

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
    evbase = event_base_new();
    wxFrame *f = new SsdpFrame(evbase, NULL, wxID_ANY, wxT(""));
    SetTopWindow(f);
    f->Show();
    timer = new MyTimer(evbase);
    timer->Start(100);
    return true;
}

int MyApp::OnExit()
{
    timer->Stop();
    delete timer;
    event_base_free(evbase);
    return 0;
}

